package com.cmc.cloud.cmclink.doc.api.document;

import com.cmc.cloud.cmclink.doc.api.document.emums.BookingOpenStatusEnum;
import com.cmc.cloud.cmclink.doc.api.document.rep.VoyageBsaRespDto;
import com.cmc.cloud.cmclink.doc.api.document.req.VoyageBsaReqDto;
import com.cmc.cloud.cmclink.doc.convert.VoyageBsaConvert;
import com.cmc.cloud.cmclink.doc.entity.VoyageBsaDO;
import com.cmc.cloud.cmclink.doc.mapper.VoyageBsaMapper;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.mybatis.core.query.LambdaQueryWrapperX;
import liquibase.pro.packaged.V;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 开仓状态查询
 *
 * @author lzp
 */
@RestController
@Validated
public class VoyageBsaApiImpl implements VoyageBsaApi {

    @Resource
    private VoyageBsaMapper voyageBsaMapper;

    @Override
    public CommonResult<List<VoyageBsaRespDto>> voyageBsaQuery(VoyageBsaReqDto voyageBsaReqDto) {
        LambdaQueryWrapperX<VoyageBsaDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        lambdaQueryWrapperX.inIfPresent(VoyageBsaDO::getVoyage, voyageBsaReqDto.getVoyages())
                .inIfPresent(VoyageBsaDO::getLaneCode, voyageBsaReqDto.getLaneCodes())
                .inIfPresent(VoyageBsaDO::getVesselCode, voyageBsaReqDto.getVesselCodes())
                .eqIfPresent(VoyageBsaDO::getBookingOpenStatus, voyageBsaReqDto.getBookingOpenStatus());
        List<VoyageBsaDO> voyageBsaDOList = voyageBsaMapper.selectList(lambdaQueryWrapperX);
        if (CollectionUtils.isEmpty(voyageBsaDOList)) {
            return CommonResult.success(Collections.emptyList());
        }
        List<VoyageBsaRespDto> voyageBsaRespDtoList = VoyageBsaConvert.INSTANCE.convertVoyageBsaRespDto(voyageBsaDOList);
        return CommonResult.success(voyageBsaRespDtoList);
    }
}
